package com.vois.jack.btmgr.devices.WLBleDfuDevice;

import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;

public interface DfuConstant {
    // Since the DFU Library version 0.5 both HEX and BIN files are supported.
    // As both files have the same MIME TYPE the distinction is made based on the file extension.
    String MIME_TYPE_OCTET_STREAM = "application/octet-stream";
    String MIME_TYPE_ZIP = "application/zip";
    /**
     * <p>
     * The file contains a new version of Soft Device.
     * <p>
     * Since DFU Library 7.0 all firmware may contain an Init packet. The Init packet is required
     * if Extended Init Packet is used by the DFU bootloader (SDK 7.0+)..
     * The Init packet for the bootloader must be placed in the .dat file.
     *
     */
    int TYPE_SOFT_DEVICE = 0x01;
    /**
     * <p>
     * The file contains a new version of Bootloader.
     * <p>
     * Since DFU Library 7.0 all firmware may contain an Init packet. The Init packet is required
     * if Extended Init Packet is used by the DFU bootloader (SDK 7.0+).
     * The Init packet for the bootloader must be placed in the .dat file.
     *
     */
    int TYPE_BOOTLOADER = 0x02;
    /**
     * <p>
     * The file contains a new version of Application.
     * <p>
     * Since DFU Library 0.5 all firmware may contain an Init packet. The Init packet is required
     * if Extended Init Packet is used by the DFU bootloader (SDK 7.0+).
     * The Init packet for the application must be placed in the .dat file.
     *
     */
    int TYPE_APPLICATION = 0x04;
    /**
     * <p>
     * A ZIP file that consists of more than 1 file. Since SDK 8.0 the ZIP Distribution packet is
     * a recommended way of delivering firmware files. Please, see the DFU documentation for
     * more details. A ZIP distribution packet may be created using the 'nrf utility' command line
     * application, that is a part of Master Control Panel 3.8.0.
     * For backwards compatibility this library supports also ZIP files without the manifest file.
     * Instead they must follow the fixed naming convention:
     * The names of files in the ZIP must be: <b>softdevice.hex</b> (or .bin), <b>bootloader.hex</b>
     * (or .bin), <b>application.hex</b> (or .bin) in order to be read correctly. Using the
     * Soft Device v7.0.0+ the Soft Device and Bootloader may be updated and sent together.
     * In case of additional application file included, the service will try to send Soft Device,
     * Bootloader and Application together (which is not supported currently) and if it fails,
     * send first SD+BL, reconnect and send the application in the following connection.
     * <p>
     * Since the DFU Library 0.5 you may specify the Init packet, that will be send prior to the
     * firmware. The init packet contains some verification data, like a device type and revision,
     * application version or a list of supported Soft Devices. The Init packet is required if
     * Extended Init Packet is used by the DFU bootloader (SDK 7.0+).
     * In case of using the compatibility ZIP files the Init packet for the Soft Device and Bootloader
     * must be in the 'system.dat' file while for the application in the 'application.dat' file
     * (included in the ZIP). The CRC in the 'system.dat' must be a CRC of both BIN contents if
     * both a Soft Device and a Bootloader is present.
     *
     */
    int TYPE_AUTO = 0x00;
    /**
     * An extra field with progress and error information used in broadcast events.
     */
    String EXTRA_DATA = "no.nordicsemi.android.dfu.extra.EXTRA_DATA";
    /**
     * An extra field to send the progress or error information in the DFU notification.
     * The value may contain:
     * <ul>
     * <li>Value 0 - 100 - percentage progress value</li>
     * <li>One of the following status constants:
     * <ul>
     * <li>{@link #PROGRESS_CONNECTING}</li>
     * <li>{@link #PROGRESS_STARTING}</li>
     * <li>{@link #PROGRESS_ENABLING_DFU_MODE}</li>
     * <li>{@link #PROGRESS_VALIDATING}</li>
     * <li>{@link #PROGRESS_DISCONNECTING}</li>
     * <li>{@link #PROGRESS_COMPLETED}</li>
     * <li>{@link #PROGRESS_ABORTED}</li>
     * </ul>
     * </li>
     * <li>An error code with {@link #ERROR_MASK} if initialization error occurred</li>
     * <li>An error code with {@link #ERROR_REMOTE_MASK} if remote DFU target returned an error</li>
     * <li>An error code with {@link #ERROR_CONNECTION_MASK} if connection error occurred
     * (e.g. GATT error (133) or Internal GATT Error (129))</li>
     * </ul>
     * To check if error occurred use:<br>
     * {@code boolean error = progressValue >= DfuBaseService.ERROR_MASK;}
     */
    String EXTRA_PROGRESS = "no.nordicsemi.android.dfu.extra.EXTRA_PROGRESS";
    /**
     * The number of currently transferred part. The SoftDevice and Bootloader may be send
     * together as one part. If user wants to upload them together with an application it has to be
     * sent in another connection as the second part.
     *
     */
    String EXTRA_PART_CURRENT = "no.nordicsemi.android.dfu.extra.EXTRA_PART_CURRENT";
    /**
     * Number of parts in total.
     *
     */
    String EXTRA_PARTS_TOTAL = "no.nordicsemi.android.dfu.extra.EXTRA_PARTS_TOTAL";
    /**
     * The current upload speed in bytes/millisecond.
     */
    String EXTRA_SPEED_B_PER_MS = "no.nordicsemi.android.dfu.extra.EXTRA_SPEED_B_PER_MS";
    /**
     * The average upload speed in bytes/millisecond for the current part.
     */
    String EXTRA_AVG_SPEED_B_PER_MS = "no.nordicsemi.android.dfu.extra.EXTRA_AVG_SPEED_B_PER_MS";


    String EXTRA_VERSION = "no.nordicsemi.android.dfu.extra.EXTRA_VERSION";

    String EXTRA_RSSI	 = "no.nordicsemi.android.dfu.extra.EXTRA_RSSI";

    /**
     * The broadcast message contains the following extras:
     * <ul>
     * <li>{@link #EXTRA_DATA} - the progress value (percentage 0-100) or:
     * <ul>
     * <li>{@link #PROGRESS_CONNECTING}</li>
     * <li>{@link #PROGRESS_STARTING}</li>
     * <li>{@link #PROGRESS_ENABLING_DFU_MODE}</li>
     * <li>{@link #PROGRESS_VALIDATING}</li>
     * <li>{@link #PROGRESS_DISCONNECTING}</li>
     * <li>{@link #PROGRESS_COMPLETED}</li>
     * <li>{@link #PROGRESS_ABORTED}</li>
     * </ul>
     * </li>
     * <li>{@link #EXTRA_PART_CURRENT} - the number of currently transmitted part</li>
     * <li>{@link #EXTRA_PARTS_TOTAL} - total number of parts that are being sent, e.g. if a ZIP
     * file contains a Soft Device, a Bootloader and an Application, the SoftDevice and Bootloader
     * will be send together as one part. Then the service will disconnect and reconnect to the
     * new Bootloader and send the application as part number two.</li>
     * <li>{@link #EXTRA_SPEED_B_PER_MS} - current speed in bytes/millisecond as float</li>
     * <li>{@link #EXTRA_AVG_SPEED_B_PER_MS} - the average transmission speed in bytes/millisecond
     * as float</li>
     * </ul>
     */
    String BROADCAST_PROGRESS = "no.nordicsemi.android.dfu.broadcast.BROADCAST_PROGRESS";
    /**
     * Service is connecting to the remote DFU target.
     */
    int PROGRESS_CONNECTING = -1;
    /**
     * Service is enabling notifications and starting transmission.
     */
    int PROGRESS_STARTING = -2;
    /**
     * Service has triggered a switch to bootloader mode. Now the service waits for the link loss
     * event (this may take up to several seconds) and will connect again to the same device,
     * now started in the bootloader mode.
     */
    int PROGRESS_ENABLING_DFU_MODE = -3;
    /**
     * Service is sending validation request to the remote DFU target.
     */
    int PROGRESS_VALIDATING = -4;
    /**
     * Service is disconnecting from the DFU target.
     */
    int PROGRESS_DISCONNECTING = -5;
    /**
     * The connection is successful.
     */
    int PROGRESS_COMPLETED = -6;
    /**
     * The upload has been aborted. Previous software version will be restored on the target.
     */
    int PROGRESS_ABORTED = -7;


    int PROGRESS_GET_VERSION = -8;

    int PROGRESS_RSSI_GET = -9;

    int PROGRESS_CONFIRM = -10;

    /**
     * The broadcast error message contains the following extras:
     * <ul>
     * representation.</li>
     * </ul>
     */
    String BROADCAST_ERROR = "no.nordicsemi.android.dfu.broadcast.BROADCAST_ERROR";
    /**
     * The type of the error. This extra contains information about that kind of error has occurred.
     * Connection state errors and other errors may share the same numbers. For example, the
     * {@link BluetoothGattCallback#onCharacteristicWrite(BluetoothGatt, BluetoothGattCharacteristic, int)}
     * method may return a status code 8 (GATT INSUF AUTHORIZATION), while the status code 8
     * returned by {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)}
     * is a GATT CONN TIMEOUT error.
     */
    String EXTRA_ERROR_TYPE = "no.nordicsemi.android.dfu.extra.EXTRA_ERROR_TYPE";
    int ERROR_TYPE_OTHER = 0;
    int ERROR_TYPE_COMMUNICATION_STATE = 1;
    int ERROR_TYPE_COMMUNICATION = 2;
    int ERROR_TYPE_DFU_REMOTE = 3;
    /**
     * If this bit is set than the progress value indicates an error.
     * to obtain error name.
     */
    int ERROR_MASK = 0x1000;
    int ERROR_DEVICE_DISCONNECTED = ERROR_MASK; // | 0x00;
    int ERROR_FILE_NOT_FOUND = ERROR_MASK | 0x01;
    /**
     * Thrown if service was unable to open the file ({@link java.io.IOException} has been thrown).
     */
    int ERROR_FILE_ERROR = ERROR_MASK | 0x02;
    /**
     * Thrown when input file is not a valid HEX or ZIP file.
     */
    int ERROR_FILE_INVALID = ERROR_MASK | 0x03;
    /**
     * Thrown when {@link java.io.IOException} occurred when reading from file.
     */
    int ERROR_FILE_IO_EXCEPTION = ERROR_MASK | 0x04;
    /**
     * Error thrown when {@code gatt.discoverServices();} returns false.
     */
    int ERROR_SERVICE_DISCOVERY_NOT_STARTED = ERROR_MASK | 0x05;
    /**
     * Thrown when the service discovery has finished but the DFU service has not been found.
     * The device does not support DFU of is not in DFU mode.
     */
    int ERROR_SERVICE_NOT_FOUND = ERROR_MASK | 0x06;
    /**
     * Thrown when unknown response has been obtained from the target. The DFU target must follow
     * specification.
     */
    int ERROR_INVALID_RESPONSE = ERROR_MASK | 0x08;
    /**
     * Thrown when the the service does not support given type or mime-type.
     */
    int ERROR_FILE_TYPE_UNSUPPORTED = ERROR_MASK | 0x09;
    /**
     * Thrown when the the Bluetooth adapter is disabled.
     */
    int ERROR_BLUETOOTH_DISABLED = ERROR_MASK | 0x0A;
    /**
     * DFU Bootloader version 0.6+ requires sending the Init packet. If such bootloader version is
     * detected, but the init packet has not been set this error is thrown.
     */
    int ERROR_INIT_PACKET_REQUIRED = ERROR_MASK | 0x0B;
    /**
     * Thrown when the firmware file is not word-aligned. The firmware size must be dividable by
     * 4 bytes.
     */
    int ERROR_FILE_SIZE_INVALID = ERROR_MASK | 0x0C;
    /**
     * Thrown when the received CRC does not match with the calculated one. The service will try
     * 3 times to send the data, and if the CRC fails each time this error will be thrown.
     */
    int ERROR_CRC_ERROR = ERROR_MASK | 0x0D;
    /**
     * Thrown when device had to be paired before the DFU process was started.
     */
    int ERROR_DEVICE_NOT_BONDED = ERROR_MASK | 0x0E;
    /**
     * Flag set when the DFU target returned a DFU error. Look for DFU specification to get error
     * codes. The error code is binary OR-ed with one of: {@link #ERROR_REMOTE_TYPE_LEGACY},
     * {@link #ERROR_REMOTE_TYPE_SECURE} or {@link #ERROR_REMOTE_TYPE_SECURE_EXTENDED}.
     */
    int ERROR_REMOTE_MASK = 0x2000;
    int ERROR_REMOTE_TYPE_LEGACY = 0x0100;
    int ERROR_REMOTE_TYPE_SECURE = 0x0200;
    int ERROR_REMOTE_TYPE_SECURE_EXTENDED = 0x0400;
    int ERROR_REMOTE_TYPE_SECURE_BUTTONLESS = 0x0800;
    /**
     * The flag set when one of {@link BluetoothGattCallback} methods was called
     * with status other than {@link BluetoothGatt#GATT_SUCCESS}.
     */
    int ERROR_CONNECTION_MASK = 0x4000;
    /**
     * The flag set when the
     * {@link BluetoothGattCallback#onConnectionStateChange(BluetoothGatt, int, int)}
     * method was called with status other than {@link BluetoothGatt#GATT_SUCCESS}.
     */
    int ERROR_CONNECTION_STATE_MASK = 0x8000;
    /**
     * The log events are only broadcast when there is no nRF Logger installed.
     * The broadcast contains 2 extras:
     * <ul>
     * <li>{@link #EXTRA_LOG_LEVEL} - The log level, one of following: {@link #LOG_LEVEL_DEBUG},
     * {@link #LOG_LEVEL_VERBOSE}, {@link #LOG_LEVEL_INFO}, {@link #LOG_LEVEL_APPLICATION},
     * {@link #LOG_LEVEL_WARNING}, {@link #LOG_LEVEL_ERROR}</li>
     * <li>{@link #EXTRA_LOG_MESSAGE} - The log message</li>
     * </ul>
     */
    /**
     * Activity may broadcast this broadcast in order to pause, resume or abort DFU process.
     * Use {@link #EXTRA_ACTION} extra to pass the action.
     */
    String BROADCAST_ACTION = "no.nordicsemi.android.dfu.broadcast.BROADCAST_ACTION";
    /**
     * The action extra. It may have one of the following values: {@link #ACTION_PAUSE},
     * {@link #ACTION_RESUME}, {@link #ACTION_ABORT}.
     */
    String EXTRA_ACTION = "no.nordicsemi.android.dfu.extra.EXTRA_ACTION";
    /**
     * Pauses the upload. The service will wait for broadcasts with the action set to
     * {@link #ACTION_RESUME} or {@link #ACTION_ABORT}.
     */
    int ACTION_PAUSE = 0;
    /** Resumes the upload that has been paused before using {@link #ACTION_PAUSE}. */
    int ACTION_RESUME = 1;
    /**
     * Aborts the upload. The service does not need to be paused before.
     * After sending {@link #BROADCAST_ACTION} with extra {@link #EXTRA_ACTION} set to this value
     * the DFU bootloader will restore the old application (if there was already an application).
     * Be aware, that uploading the Soft Device will erase the application in order to make space
     * in the memory. In case there is no application, or the application has been removed, the
     * DFU bootloader will be started and user may try to send the application again.
     * The bootloader may advertise with the address incremented by 1 to prevent caching services.
     */
    int ACTION_ABORT = 2;
}
